﻿IF EXISTS (SELECT * FROM sysobjects WHERE type = 'P' AND name = 'P_UpdateUserMenu')
	BEGIN
		DROP  Procedure  [esf_sso].P_UpdateUserMenu
	END

GO

CREATE Procedure [esf_sso].P_UpdateUserMenu
	@pID	INT

	,@pParentCode			VARCHAR (60)
	,@pCode					VARCHAR (60)
	,@pName					VARCHAR (60)
	,@pDescription			VARCHAR (600) = NULL
	,@pExtra_I				VARCHAR (500) = NULL
	,@pURL					VARCHAR (500) = NULL
	,@pIsEnabled			BIT = 1
	,@pIconURL				VARCHAR (4000) = NULL
	,@pHeaderURL			VARCHAR (4000) = NULL	
	,@pUserLastUpdateAlias	VARCHAR (20) = 'root'
	,@pLastUpdateDateTime	DATETIME = NULL
AS
	
	EXEC esf_sso.P_UpdateBasicReference
		@pID, 7
		,@pCode, @pName, @pDescription
		,@pExtra_I, @pURL, NULL
		,@pIsEnabled
		,@pUserLastUpdateAlias, @pLastUpdateDateTime

	-- DECLARE @ImageID INT


	-- DELETE FROM esf_sso.BasicReference_File WHERE BasicReferenceID = @pID


	--IF @pIconURL IS NOT NULL
	--BEGIN
	--	SELECT @ImageID = ID FROM esf_files.[File] WHERE URL = @pIconURL

	--	IF @ImageID IS NULL
	--	BEGIN
	--		INSERT INTO esf_files.[File] (FileTypeID, URL)
	--		SELECT
	--			(SELECT ID FROM esf_sso.VFileCategory WHERE Code = 'Icon_16x16')
	--			,@pIconURL
			
	--		SET @ImageID = @@IDENTITY
	--	END

	--	INSERT INTO esf_sso.BasicReference_File (BasicReferenceID, FileID)
	--	VALUES (@pID, @ImageID)
	--END
	
	
	--IF @pHeaderURL IS NOT NULL 
	--BEGIN
	--	SELECT @ImageID = ID FROM esf_files.[File] WHERE URL = @pHeaderURL

	--	IF @ImageID IS NULL
	--	BEGIN
	--		INSERT INTO esf_files.[File] (FileTypeID, URL)
	--		SELECT
	--			(SELECT ID FROM esf_sso.VFileCategory WHERE Code = 'Header_400x50')
	--			,@pHeaderURL

	--		SET @ImageID = @@IDENTITY
	--	END

	--	INSERT INTO esf_sso.BasicReference_File (BasicReferenceID, FileID)
	--	VALUES (@pID, @ImageID)
	--END
GO